package com.lzm.ydpt.mvp.presenterimpl;

import com.byt.framlib.basemvp.BasePresenter;
import com.byt.framlib.basemvp.basebean.BaseResponseBean;
import com.byt.framlib.basemvp.exception.ApiException;
import com.byt.framlib.basemvp.listener.OnLoadingErrorListener;
import com.byt.framlib.basemvp.listener.OnLoadingProgressListener;
import com.lzm.ydpt.entity.UserInfo;
import com.lzm.ydpt.module.common.WelActivity;
import com.lzm.ydpt.mvp.api.ProgressSubscriber;
import com.lzm.ydpt.mvp.contract.WelContract;
import com.lzm.ydpt.mvp.modelimpl.WelModelImpl;

import java.util.List;

import okhttp3.RequestBody;

/**
 * 类名称：WelPresenterImpl
 * 类描述：代理实现
 */
public class WelPresenterImpl extends BasePresenter implements WelContract.Presenter {

    private WelContract.View mView;
    private WelContract.Model mModel;

    public WelPresenterImpl(WelActivity context) {
        super(context);
        this.mView = context;
        this.mModel = new WelModelImpl();
    }

    @Override
    public void onWel(RequestBody body) {
        mManager.http(mModel.onWel(body), getLifecycleProvider(), new ProgressSubscriber<>(mContext, new OnLoadingProgressListener<List<UserInfo>>() {
            @Override
            public void onLoadingResult(BaseResponseBean<List<UserInfo>> entity) {
                mView.onWel(entity.getData());
            }
        }, new OnLoadingErrorListener() {
            @Override
            public void onError(ApiException e, String method) {
                mView.showMessage(e.getDisplayMessage(), method);
            }

            @Override
            public void onErrorResult(BaseResponseBean entity, String method) {
                mView.showMessage(entity.getMessage(), method);
            }
        }, "onWel"));
    }
}